﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using DACNPM.ReportFile;

namespace DACNPM.MyUserControl.UCHienThi
{
    public partial class UCThongKeNhapKho : UserControl
    {
        Thongke2BUO tk2BUO = new Thongke2BUO();
        public UCThongKeNhapKho()
        {
            InitializeComponent();
            showCbbNCC();
            //dataGridView1.AutoGenerateColumns = false;
            //DateTime tuNgay = DateTime.Parse(dateTimePicker1.Text);
            //DateTime denNgay = DateTime.Parse(dateTimePicker2.Text);
            //dataGridView1.DataSource = tk2BUO.HienThiNhapKhoAll(tuNgay, denNgay);
        }

        private void rdAll_CheckedChanged(object sender, EventArgs e)
        {
            //rdXemTheoNhaCungCap.Checked = false;
            cbbNCC.Enabled = false;
            //dataGridView1.AutoGenerateColumns = false;
            //DateTime tuNgay = DateTime.Parse(dateTimePicker1.Text);
            //DateTime denNgay = DateTime.Parse(dateTimePicker2.Text);
            //dataGridView1.DataSource = tk2BUO.HienThiNhapKhoAll(tuNgay, denNgay);
        }

        private void rdXemTheoNhaCungCap_CheckedChanged(object sender, EventArgs e)
        {
            //rdAll.Checked = false;
            cbbNCC.Enabled = true;

            //String idNCC = cbbNCC.SelectedValue.ToString();
            //dataGridView1.AutoGenerateColumns = false;
            //DateTime tuNgay=DateTime.Parse(dateTimePicker1.Text);
            //DateTime denNgay=DateTime.Parse(dateTimePicker2.Text);
            //dataGridView1.DataSource = tk2BUO.HienThiNhapKhoTheoNCC(idNCC,tuNgay,denNgay);
        }

        void showCbbNCC()
        {
            NhaCungCapBUO ncc=new NhaCungCapBUO();

            cbbNCC.DataSource = ncc.GetAll();
            cbbNCC.DisplayMember = "TenNhaCungCap";
            cbbNCC.ValueMember = "id_NhaCungCap";
        }

        private void cbbNCC_SelectedIndexChanged(object sender, EventArgs e)
        {
            String idNCC = cbbNCC.SelectedValue.ToString();
            dataGridView1.AutoGenerateColumns = false;
            //DateTime tuNgay = DateTime.Parse(dateTimePicker1.Text);
            //DateTime denNgay = DateTime.Parse(dateTimePicker2.Text);
            //dataGridView1.DataSource = tk2BUO.HienThiNhapKhoTheoNCC(idNCC, tuNgay, denNgay);
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            DateTime tuNgay = DateTime.Parse(dateTimePicker1.Text);
            DateTime denNgay = DateTime.Parse(dateTimePicker2.Text);
            if(rdAll.Checked)
            {
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = tk2BUO.HienThiNhapKhoAll(tuNgay, denNgay);
            }
            else if(rdXemTheoNhaCungCap.Checked)
            {
                String idNCC = cbbNCC.SelectedValue.ToString();
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = tk2BUO.HienThiNhapKhoTheoNCC(idNCC, tuNgay, denNgay);
            }
            else
            {
                MessageBox.Show("loi roi");
            }
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            if (rdAll.Checked==true)
            {
                ThongKeNhapKhoReport r = new ThongKeNhapKhoReport();
                r.DataSource = dataGridView1.DataSource;
                r.Load(dateTimePicker1.Text,dateTimePicker2.Text);
                r.ShowPreviewDialog();
            }

            if (rdXemTheoNhaCungCap.Checked==true)
            {
                ThongKeNhapKhoTheoNCCReport r = new ThongKeNhapKhoTheoNCCReport();
                r.DataSource = dataGridView1.DataSource;
                r.Load(cbbNCC.Text,dateTimePicker1.Text,dateTimePicker2.Text);
                r.ShowPreviewDialog();
            }
        }

        
    }
}
